<?php
namespace app\client\controller;

use think\Url;
use think\Request;
use think\Session;
use think\Controller;
use app\client\model\Member as MemberModel;

class Login extends Controller
{
    // 前置方法
    protected $beforeActionList = [
        'checkLogin' => ['only' => 'index'],
    ];


    /**
     * 商铺登录
     * @param Request $request
     * @param MemberModel $member
     * @return mixed
     */
    public function index(Request $request,MemberModel $member)
    {
        Session::set('shop_id', 711);
        if ($request->instance()->isPost()) {
            if ($member::login()) {
                win('登录成功', Url::build('client/dashboard/index'));

            } else {

                fail('登录失败');
            }

        }


        return $this->fetch('', [
            "mate_title" => '商铺登录'
        ]);
    }


    /**
     * 检测用户是否登录
     */
    protected function checkLogin()
    {
        if (true === Session::has('shop_id')) {
            $this->redirect(Url::build('client/dashboard/index'));
        }
    }


    /**
     * 注销登录
     */
    public function logout()
    {
        Session::delete('shop_id');
        $this->redirect(Url::build('client/login/index'));
    }
}
